package com.rp.system.user.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;

import java.time.LocalDateTime;
import java.io.Serializable;
import java.util.*;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.rp.common.aspect.annotetion.Dict;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * <p>
 * 菜单权限表
 * </p>
 *
 * @author vicente
 * @since 2020-11-24
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "SysPermission对象", description = "菜单权限表")
public class SysPermission extends Model<SysPermission> {

    //private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.UUID)
    @ApiModelProperty(value = "主键id")
    private String id;

    @ApiModelProperty(value = "父id")
    private String parentId;

    @ApiModelProperty(value = "菜单标题")
    private String name;

    @ApiModelProperty(value = "路径")
    private String url;

    @ApiModelProperty(value = "组件")
    private String component;

    @ApiModelProperty(value = "组件名字")
    private String componentName;

    @ApiModelProperty(value = "一级菜单跳转地址")
    private String redirect;

    @Dict(dicCode = "menu_type")
    @ApiModelProperty(value = "菜单类型(0:一级菜单; 1:子菜单; 2:按钮/权限)", example = "0")
    private Integer menuType;

    @ApiModelProperty(value = "菜单权限编码")
    private String perms;

    @ApiModelProperty(value = "权限策略1显示2禁用", example = "1")
    private Integer permsType;

    @ApiModelProperty(value = "菜单排序", example = "0.0")
    private Double sortNo;

    @ApiModelProperty(value = "聚合子路由: 1是0否", example = "1")
    private Integer alwaysShow;

    @ApiModelProperty(value = "菜单图标")
    private String icon;

    @ApiModelProperty(value = "是否路由菜单: 0:不是  1:是", example = "1")
    private Integer isRoute;

    @ApiModelProperty(value = "是否叶子节点:1:是  0:不是", example = "1")
    private Integer isLeaf;

    @ApiModelProperty(value = "是否缓存该页面:1:是   0:不是", example = "0")
    private Integer keepAlive;

    @ApiModelProperty(value = "是否隐藏路由: 0否,1是", example = "0")
    private Boolean hidden;

    @ApiModelProperty(value = "描述")
    private String description;

    @ApiModelProperty(value = "创建人")
    @TableField(fill = FieldFill.INSERT)
    private String createBy;

    @ApiModelProperty(value = "创建时间")
    @TableField(fill = FieldFill.INSERT)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private LocalDateTime createTime;

    @ApiModelProperty(value = "更新人")
    @TableField(fill = FieldFill.UPDATE)
    private String updateBy;

    @ApiModelProperty(value = "更新时间")
    @TableField(fill = FieldFill.UPDATE)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private LocalDateTime updateTime;

    @TableLogic
    @ApiModelProperty(value = "删除状态 0正常 1已删除", example = "0")
    private Integer delFlag;

    @ApiModelProperty(value = "是否添加数据权限1是0否", example = "1")
    private Integer ruleFlag;

    @ApiModelProperty(value = "按钮权限状态(0无效1有效)", example = "1")
    private Integer status;

    @ApiModelProperty(value = "外链菜单打开方式 0/内部打开 1/外部打开", example = "0")
    private Integer internalOrExternal;


//    @JsonIgnore
//    @TableField(exist = false)
//    private Set<SysRole> roles = new HashSet<>();


    @ApiModelProperty(value = "子节点列表", hidden = true)
    @TableField(exist = false)
    private LinkedHashSet<SysPermission> children;

    @ApiModelProperty(value = "宽度", hidden = true)
    @TableField(exist = false)
    private String weight;

    @Override
    protected Serializable pkVal() {
        return this.id;
    }


}
